<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>我的任务</title>
<!-- 360浏览器以极速模式显示 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/matrix-style.css" />
<link rel="stylesheet" href="css/matrix-media.css" />
<link rel="stylesheet" href="jquery-easyui/themes/default/easyui.css" />
<link rel="stylesheet" href="jquery-easyui/themes/icon.css" />
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
<script charset="utf-8" src="editor/kindeditor-all.js"></script>
<script charset="utf-8" src="editor/lang/zh-CN.js"></script>
<link type="text/javascript" href="editor/themes/default/default.css"></link>
<script type="text/javascript" src="editor/plugins/code/prettify.js"></script>
<style>

/*easyui*/
#fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
} 
</style>

<script>
function logout(){
		$.messager.confirm('Confirm','Are you sure you want to logout?',function(r){
            if (r){
                $.post('<%=request.getContextPath()%>/logout',function(result) {
					if (result.success) {
						$.messager.show({ // show error message
							title : '提示',
							msg : '退出成功'
						});
			           }
				 else {
						$.messager.show({ // show error message
									title : '提示',
									msg : '登录已过期，重新登录'
								});
					   }
				}, 'json');
    			window.open('<%=request.getContextPath()%>/index.jsp','_self');

		     }
	});
}

</script>
<script type="text/javascript">
$(document).ready(function(){
	$('#dg').datagrid({
		    title:'我的任务',
	        width:'100%',
		    pagination:true,
		    rownumbers:true,
		    fitColumns:true,
		    singleSelect:true,
		    idField:'id',
		    url:'<%=request.getContextPath()%>/task?method=assist-tasklist&assistid=${sessionScope.assist.id}',
		    columns:[[
		        {field:'id',title:'编号'},
		        {field:'name',title:'任务名称' },
		        {field:'content',title:'任务内容',hidden:true},
		        {field:'backinfo',title:'备注',hidden:true},
		        {field:'startdate',title:'任务发起时间'},
		        {field:'due',title:'任务到期时间'},
		        {field:'assistid',title:'任务负责人'},
		        {field:'status',title:'当前状态',
					styler:function(value,row,index){
						return 'color:red;';
					},
	               formatter:function(value,row,index){
	            	   switch (value) {
						case 0:
							return "未开启";
							break;
						case 1:
							return "已启动";
							break;
						case 2:
							return "处理中";
							break;
						case 3:
							return "被驳回";
							break;
						case 4:
							return "待审核";
							break;
						case 5:
							return '结束';
							break;
						default:
							break;
						}
		          
		            }
		        },
		        {field:'do',title:'操作',width:70,align:'center',
		            formatter:function(value,row,index){
		                if (true){
		                    var q = '<a href="#" style="color:blue;" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="accept('+index+')">接受</a>  ';
		                    var z = '<a href="#" style="color:blue;" class="easyui-linkbutton"  onclick="reject('+index+')">驳回</a>  ';
		                    var s = '<a href="#" style="color:blue;" class="easyui-linkbutton" onclick="submitCheck('+index+')">提交审核</a>  ';
		                    return q+z+s;
		                } else {
		                    var e = '<a href="#" onclick="editrow('+index+')">Edit</a> ';
		                    var d = '<a href="#" onclick="deleterow('+index+')">Delete</a>';
		                    return e+d;
		                }
		            }
		        }
		    ]],

		});
	

 //headmenu
var ddlMenu1 = $('#li1').menubutton({ menu: '#cusmenu1' }); 
var ddlMenu2 = $('#li2').menubutton({ menu: '#cusmenu2' }); 
//menubutton 依赖于 menu、linkbutton 这两个插件，所以我们可以这样搞定她
$(ddlMenu1.menubutton('options').menu).menu({
            onClick: function (item) {
                window.open("<%=request.getContextPath()%>/task?method=assisttasks","_blank")
            }
})
});

function readTask(){
	var row = $('#dg').datagrid('getSelected');
	if(row){
	    $('#dlg2').dialog('open').dialog('setTitle','Task info');
	    $("#dlg2 .id").text(row.id);
	    $("#dlg2 .name").text(row.name);
	    $("#dlg2 .content").append(row.content);
	    $("#dlg2 .startdate").text(row.startdate);
	    $("#dlg2 .due").text(row.due);
	    $("#dlg2 .assistid").text(row.assistid);
	    $("#dlg2 .status").text(function(){
	    	switch (row.status) {
			case 0:
				return '未开启';
				break;
			case 1:
				return '已启动';
				break;
			case 2:
				return '处理中';
				break;
			case 3:
				return '被驳回';
				break;
			case 4:
				return '待审核';
				break;
				
			case 5:
				return '结束';
				break;
				
			default:
				break;
			}
	    });
	    $("#dlg2 .backinfo").append(row.backinfo);
	}
}

function accept(index){
	$("#dg").datagrid('selectRow',index);
	var row=$("#dg").datagrid("getSelected");
	if(row.status==1){
		$.messager.confirm('Confirm','Are you sure accept the task?',function(r){
			if(r){
				$.post('<%=request.getContextPath()%>/task?method=changestatus&status=2&id='+row.id,function(result){
					if(result.success){
						$.messager.show({
							title:'提示',
							msg:'您选择了接受任务，请及时处理'
								
						})
						$("#dg").datagrid('reload');
					}
				},'json');
				
			}
		})
	}else if(row.status==2){
		$.messager.show({
			title:'提示',
			msg:'您已经接受了任务，任务应该正被你处理'
		})
		
	}
		
}
 function reject(index){
	$("#dg").datagrid('selectRow',index);
	var row=$("#dg").datagrid("getSelected");
	if(row.status==1||row.status==2){
		$.messager.confirm('Confirm','Are you sure reject the task?',function(r){
			if(r){
				$("#dlg3").dialog('open');
				 KindEditor.create("#editor_id3",{
					 cssPath:'editor/plugins/code/prettify.css',
			 		 resize:0,
					 uploadJson:'editor/jsp/upload_json.jsp',
				     fileManagerJson : 'editor/jsp/file_manager_json.jsp',
					 allowPreviewEmoticons:true,
					 allowImageUpload:true,			
					 width:'100%',
					 afterBlur:function() {
					      this.sync();
					  }
					 }) ; 
				url='<%=request.getContextPath()%>/task?method=changestatus&status=3&id='+row.id;
			}
		})
	}
} 
function doreject(){
	$('#fm3').form('submit',{
		url:url,
		onSubmit:function(){
		},
		success:function(result){
            var result = eval('('+result+')');
            if(result.success){
            	$.messager.show({
            		title:'提示',
            		msg:'成功驳回了'
            	})
            	$("#dlg3").dialog('close');
            	$("#dg").datagrid('reload');
            }else {
            	$.messager.show({
            		title:'提示',
            		msg:'驳回失败，请重试'
            	})
            }
		}
	})
}

function submitCheck(index){
	$("#dg").datagrid('selectRow',index);
	var row=$("#dg").datagrid("getSelected");
	if(row.status==2){
		$.messager.confirm('Confirm','Are you sure accept the task?',function(r){
			if(r){
				$("#dlg4").dialog('open');
				KindEditor.create("#editor_id4",{
					 cssPath:'editor/plugins/code/prettify.css',
			 		 resize:0,
					 uploadJson:'editor/jsp/upload_json.jsp',
				     fileManagerJson : 'editor/jsp/file_manager_json.jsp',
					 allowPreviewEmoticons:true,
					 allowImageUpload:true,			
					 width:'100%',
					 afterBlur:function() {
					      this.sync();
					  }
					 }) ; 
				url='<%=request.getContextPath()%>/task?method=changestatus&status=4&id='+row.id;
			 }
		});
	}else{
		$.messager.show({
			title:'提示',
			msg:'您还未接受该任务，不允许提交审核'
		})
	}
	
}
function sendCheck(){
	$('#fm4').form('submit',{
		url:url,
		onSubmit:function(){
		},
		success:function(result){
            var result = eval('('+result+')');
            if(result.success){
            	$.messager.show({
            		title:'提示',
            		msg:'提交完成，待审核'
            	})
            	$("#dlg4").dialog('close');
            	$("#dg").datagrid('reload');
            }else {
            	$.messager.show({
            		title:'提示',
            		msg:'提交失败，重试'
            		
            	})
            }
            

		}
	})
}
</script>


</head>
<body>
<!--Header-part-->
<div id="header">
	<h1><a style="height:31px;" href="<%=request.getContextPath() %>/dashboard"></a></h1>
</div>
<!--close-Header-part-->

<!--top-Header-menu-->
<ul style="position:absolute;left:200px;top:20px;list-style:none;">
<c:choose>
 <c:when test="${sessionScope.assist.type eq 1}">
   <li id="li1" style="float:left;padding:5px;color:#0094ff;font-size:12px;" icon="icon-lightning">welcome you</li>
  <div id="cusmenu1" style="width:150px;">
   <div id="id1">我的资料</div>
   <div id="id2">我的任务</div>
   <div class="menu-sep"></div>
</div>
 </c:when>
 <c:otherwise></c:otherwise>
</c:choose>
 <li id="li2" style="float:left;padding:5px;color:#0094ff;font-size:12px;" icon="icon-lightning">message</li>
 <li style="float:left;padding:5px;color:#0094ff;font-size:12px;" class="easyui-linkbutton" data-options="plain:true" onclick="logout()">logout</li>
</ul>
<div id="cusmenu2" style="width:150px;">
   <div id="id4">系统消息</div>
</div>
<!-- top menu end -->
<div id="welcome" ><h3 style="position:absolute;top:5px;right:105px;font-size:16px;color:white;">欢迎管理员   ${sessionScope.assist.id} 登录！</h3></div>

<!-- side bar start-->
<div id="sidebar">
		<ul>
			<li><a href="<%=request.getContextPath()%>/dashboard"><i
					class="icon icon-home"></i> <span>Dashboard控制面板</span></a></li>
			<li><a href="<%=request.getContextPath()%>/study?method=page"><i
					class="icon icon-signal"></i> <span>Study news留学信息</span></a></li>
			<li><a href="<%=request.getContextPath()%>/travel?method=page"><i
					class="icon icon-inbox"></i> <span>Travel New活动信息</span></a></li>
			<li><a href="<%=request.getContextPath()%>/news?method=page"><i
					class="icon icon-th"></i> <span>Recent News近期新闻</span></a></li>
			<li><a
				href="<%=request.getContextPath()%>/member?method=page&key=total"><i
					class="icon icon-fullscreen"></i> <span>Members centre会员中心</span></a></li>
			
		</ul>
	</div>
<!-- side bar end -->
<!-- content start  -->
	<div  id="content" class="easyui-layout" >
		
		<div region="center" 
			style="padding: 0px; background: #eee;">
			<table id="dg"  toolbar="#toolbar">
			</table>
			<div id="toolbar">
			        <a href="#" class="easyui-linkbutton" iconCls="icon-large-smartart"
					plain="true" onclick="readTask()">查看任务详情 </a>
			</div>
			
			
			<div id="dlg2" class="easyui-dialog"
				style="width: 500px; height: 630px; padding: 10px 20px"
				closed="true" buttons="#dlg-buttons2">
				<div class="ftitle" style="text-align: center;">任务详细信息</div>
				<table class="table table-bordered table-striped">
					<tbody>
						<tr>
						<tr>
							<td>编号:</td>
							<td class="id"></td>
						</tr>
						<tr>
							<td>名称</td>
							<td class="name"></td>
						</tr>
						<tr>
							<td>内容</td>
							<td class="content"></td>
						</tr>
						<tr>
							<td>开始时间</td>
							<td class="startdate"></td>
						</tr>
						<tr>
							<td>截止时间</td>
							<td class="due"></td>
						</tr>
						<tr>
							<td>负责人</td>
							<td class="assistid"></td>
						</tr>
						<tr>
							<td>当前状态</td>
							<td class="status"></td>
						</tr>
						<tr>
							<td>备注</td>
							<td class="backinfo"></td>
						</tr>
					</tbody>
				</table>
			</div>
			<div id="dlg-buttons2">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-cancel"
					onclick="javascript:$('#dlg2').dialog('close')" style="width: 90px">Cancel</a>
			</div>
			
			<div id="dlg3" class="easyui-dialog"
				style="width: 500px; height: 400px; padding: 10px 20px"
				closed="true" buttons="#dlg-buttons3">
				<div class="ftitle" style="text-align: center;">驳回原因</div>
				<form id="fm3" method="post" novalidate>
		        <div class="fitem">
						<label>驳回原因:</label>
					   <textarea style="float:left;"  class="easyui-kindeditor " id="editor_id3" name="content"   required="true"></textarea>
				</div>
				</form>
			</div>
			<div id="dlg-buttons3">
				<a href="javascript:void(0)" class="easyui-linkbutton c6"
					iconCls="icon-ok" onclick="doreject()" style="width: 90px">驳回</a> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-cancel"
					onclick="javascript:$('#dlg3').dialog('close')" style="width: 90px">Cancel</a>
			</div>
			
			<div id="dlg4" class="easyui-dialog"
				style="width: 500px; height: 400px; padding: 10px 20px"
				closed="true" buttons="#dlg-buttons4">
				<div class="ftitle" style="text-align: center;">提交文件审核</div>
				<form id="fm4" method="post" novalidate>
		        <div class="fitem">
					<label>完成的任务附件:</label>
					<textarea style="float:left;"  class="easyui-kindeditor " id="editor_id4" name="content"   required="true"></textarea>
				</div>
				</form>
			</div>
			<div id="dlg-buttons4">
				<a href="javascript:void(0)" class="easyui-linkbutton c6"
					iconCls="icon-ok" onclick="sendCheck()" style="width: 90px">提交审核</a> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-cancel"
					onclick="javascript:$('#dlg4').dialog('close')" style="width: 90px">Cancel</a>
			</div>
	</div>
</div>
	<div class="row-fluid">
		<div id="footer" class="span12">
			2016 &copy; <a href="http://themedesigner.in/">guangzhoushuntian
				information technology</a>
		</div>
	</div>
	<!--end-Footer-part-->
</body>
</html>
